const jwt = require("jsonwebtoken");
const { expressjwt } = require("express-jwt")

const jwt_config = {
	secretKey: "shop",
	expiresIn: 86400,
	algorithm: "HS256"
};

module.exports.authenticate = function (data) {
	// 生成认证token
	let token = jwt.sign(
		data,
		jwt_config.secretKey,
		{
			algorithm: jwt_config.algorithm,
			expiresIn: jwt_config.expiresIn
		}
	);
	return token;
}


module.exports.tokenAuth = expressjwt({
	secret: jwt_config.secretKey,
	algorithms: [jwt_config.algorithm]
});